package main

import (
	"fmt"
	"sync"
	"time"
)

var wg sync.WaitGroup

// 写
func writeData(intChan chan int) {
	defer wg.Done()
	for i := 1; i <= 50; i++ {
		intChan <- i
		fmt.Println("writeData 写入数据=", i)
	}
	close(intChan)
}

// 读
func readData(intChan chan int) {
	defer wg.Done()
	for v := range intChan {
		fmt.Println("readData 读到数据=", v)
		time.Sleep(time.Second)
	}
}

func main() {
	//声明一个管道
	var intChan chan int
	intChan = make(chan int, 50)
	wg.Add(2)
	go writeData(intChan)
	go readData(intChan)
	wg.Wait()
}
